package org.drushpal.service.commands
{
	import mx.collections.ArrayCollection;
	import mx.utils.StringUtil;
	
	import org.drushpal.model.vo.Variable;
	import org.drushpal.service.DrushService;
	import org.robotlegs.mvcs.Command;
	
	public class VGetCommand extends Command
	{
		[Inject]public var drushService:DrushService;
		[Inject]public var event:DrushCommandEvent;
		override public function execute():void{
			
			drushService.variablesCollection = new ArrayCollection();
			var vars:Array = event.output.split("$variables['");
			for each(var result:String in vars){
				try{
					if(result.length){
						var splitResult:Array = result.split("'] = ");
						var variable:Variable = new Variable();
						variable.name = splitResult[0];
						variable.value = String(splitResult[1]).substr(0,String(splitResult[1]).length-2);//trim off trailing ; and return
						drushService.variablesCollection.addItem(variable);
					}
				}catch(e:*){
					trace("can't parse variable");
				}
			}
		}
	}
}